package com.xinyirun.scm.core.system.mapper.query.ledger;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinyirun.scm.bean.system.vo.report.ledger.*;
import com.xinyirun.scm.common.constant.DictConstant;
import com.xinyirun.scm.common.constant.SystemConstants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProcessingLedgerMapper {

    /**
     * 稻谷
     * @param searchCondition
     * @param page
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t4.name out_warehouse_name,                                                                         "
            +  "    t.id,                                                                                               "
            +  "  	t8.name goods_name,                                                                                 "
            +  "  	t8.spec spec,                                                                                       "
            +  "  	ifnull(t9.contract_no,t1.contract_no) contract_no,                                                  "
            +  "  	t.out_time,                                                                                         "
            +  "  	t10.no vehicle_no,                                                                                  "
            +  "  	IFNULL(t2.qty,t3.qty) as out_qty,                                                                   "
            +  "  	t7.name in_warehouse_name,                                                                          "
            +  "  	t.in_time,                                                                                          "
            +  "  	IFNULL(t5.qty,t6.qty) as in_qty,                                                                    "
            +  "  	t.c_time                                                                                            "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN b_monitor_out t2 ON t2.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t3 ON t3.monitor_id = t.id                                               "
            +  "  LEFT JOIN m_warehouse t4 ON t1.out_warehouse_id = t4.id                                               "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t6 ON t6.monitor_id = t.id                                                 "
            +  "  LEFT JOIN m_warehouse t7 ON t7.id = t1.in_warehouse_id                                                "
            +  "  LEFT JOIN m_goods_spec t8 ON t1.sku_id = t8.id                                                        "
            +  "  LEFT JOIN b_order t9 on t9.serial_type in ('b_in_order','b_out_order') and t1.order_id = t9.id        "
            +  "  LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                                      "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
//            +  "  -- 发货类型是出库的                                                                                   "
            +  "  AND IFNULL(t2.type,t3.type) = '"+ SystemConstants.MONITOR.B_MONITOR_OUT +"'                           "
//            +  "  -- 发货仓库类型是“直属库”、“加工掺混点”                                                               "
            +  "  AND t4.warehouse_type IN ('"+ DictConstant.DICT_M_WAREHOUSE_TYPE_ZX +"', '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"')"
//            +  "  -- 收货类型是入库                                                                                     "
            +  "  AND IFNULL(t5.type,t6.type) = '"+ SystemConstants.MONITOR.B_MONITOR_IN +"'                            "
//            +  "  -- 收货仓库是“加工掺混点”                                                                             "
            +  "  AND t7.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"'                                 "
//            +  "  -- 商品编码是稻谷（zlsd-0100507-3）                                                                   "
            +  "  AND t8.`goods_code` = '"+ SystemConstants.PRODUCT_COMM_CODE.COMM_RICE_CODE +"'                        "
            +  "  AND (t1.out_warehouse_id = #{p1.out_warehouse_id} or #{p1.out_warehouse_id} is null)                  "
            +  "  AND (t1.in_warehouse_id = #{p1.in_warehouse_id} or #{p1.in_warehouse_id} is null)                     "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') >= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') <= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') >= DATE_FORMAT(#{p1.in_time_start},'%Y-%m-%d') or #{p1.in_time_start} is null)     "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') <= DATE_FORMAT(#{p1.in_time_end},'%Y-%m-%d') or #{p1.in_time_end} is null)         "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
//            +  "  AND (ifnull(t9.contract_no,t1.contract_no) LIKE CONCAT (' %', #{p1.contract_no} ,'%'}) )                     "
            + " ${p1.params.dataScopeAnnotation}                                                                        "
    )
    IPage<ProcessingRiceWarehouseInProgressVo> queryRicePageList(@Param("p1") ProcessingRiceWarehouseInProgressVo searchCondition, Page<ProcessingRiceWarehouseInProgressVo> page);

    /**
     * 稻谷 合计
     * @param searchCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	IFNULL(SUM(IFNULL(t2.qty,t3.qty)), 0) as out_qty,                                                   "
            +  "  	IFNULL(SUM(IFNULL(t5.qty,t6.qty)), 0) as in_qty                                                     "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN b_monitor_out t2 ON t2.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t3 ON t3.monitor_id = t.id                                               "
            +  "  LEFT JOIN m_warehouse t4 ON t1.out_warehouse_id = t4.id                                               "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t6 ON t6.monitor_id = t.id                                                 "
            +  "  LEFT JOIN m_warehouse t7 ON t7.id = t1.in_warehouse_id                                                "
            +  "  LEFT JOIN m_goods_spec t8 ON t1.sku_id = t8.id                                                        "
            +  "  LEFT JOIN b_order t9 on t9.serial_type in ('b_in_order','b_out_order') and t1.order_id = t9.id        "
            +  "  LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                                      "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
            +  "  AND IFNULL(t2.type,t3.type) = '"+ SystemConstants.MONITOR.B_MONITOR_OUT +"'                           "
            +  "  AND t4.warehouse_type IN ('"+ DictConstant.DICT_M_WAREHOUSE_TYPE_ZX +"', '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"')"
            +  "  AND IFNULL(t5.type,t6.type) = '"+ SystemConstants.MONITOR.B_MONITOR_IN +"'                            "
            +  "  AND t7.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"'                                 "
            +  "  AND t8.`goods_code` = '"+ SystemConstants.PRODUCT_COMM_CODE.COMM_RICE_CODE +"'                        "
            +  "  AND (t1.out_warehouse_id = #{p1.out_warehouse_id} or #{p1.out_warehouse_id} is null)                  "
            +  "  AND (t1.in_warehouse_id = #{p1.in_warehouse_id} or #{p1.in_warehouse_id} is null)                     "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') >= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') <= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') >= DATE_FORMAT(#{p1.in_time_start},'%Y-%m-%d') or #{p1.in_time_start} is null)     "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') <= DATE_FORMAT(#{p1.in_time_end},'%Y-%m-%d') or #{p1.in_time_end} is null)         "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    ProcessingRiceWarehouseInProgressVo queryRicePageListSum(@Param("p1")ProcessingRiceWarehouseInProgressVo searchCondition);

    /**
     * 稻谷
     * @param searchCondition
     * @return
     */
    @Select("<script>                                                                                                   "
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t4.name out_warehouse_name,                                                                         "
            +  "  	t8.name goods_name,                                                                                 "
            +  "  	t8.spec spec,                                                                                       "
            +  "  	ifnull(t9.contract_no,t1.contract_no) contract_no,                                                  "
            +  "  	t.out_time,                                                                                         "
            +  "  	t10.no out_vehicle_no,                                                                              "
            +  "  	IFNULL(t2.qty,t3.qty) as out_qty,                                                                   "
            +  "  	t7.name in_warehouse_name,                                                                          "
            +  "  	t.in_time,                                                                                          "
            +  "  	IFNULL(t5.qty,t6.qty) as in_qty,                                                                    "
            +  "    @row_num:= @row_num+ 1 as no,                                                                       "
            +  "  	t10.no in_vehicle_no                                                                                "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN b_monitor_out t2 ON t2.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t3 ON t3.monitor_id = t.id                                               "
            +  "  LEFT JOIN m_warehouse t4 ON t1.out_warehouse_id = t4.id                                               "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t6 ON t6.monitor_id = t.id                                                 "
            +  "  LEFT JOIN m_warehouse t7 ON t7.id = t1.in_warehouse_id                                                "
            +  "  LEFT JOIN m_goods_spec t8 ON t1.sku_id = t8.id                                                        "
            +  "  LEFT JOIN b_order t9 on t9.serial_type in ('b_in_order','b_out_order') and t1.order_id = t9.id        "
            +  "  LEFT JOIN m_vehicle t10 ON t.vehicle_id = t10.id                                                      "
            +  "   ,(select @row_num:=0) t11                                                                            "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
            +  "  AND IFNULL(t2.type,t3.type) = '"+ SystemConstants.MONITOR.B_MONITOR_OUT +"'                           "
            +  "  AND t4.warehouse_type IN ('"+ DictConstant.DICT_M_WAREHOUSE_TYPE_ZX +"', '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"')"
            +  "  AND IFNULL(t5.type,t6.type) = '"+ SystemConstants.MONITOR.B_MONITOR_IN +"'                            "
            +  "  AND t7.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"'                                 "
            +  "  AND t8.`goods_code` = '"+ SystemConstants.PRODUCT_COMM_CODE.COMM_RICE_CODE +"'                        "
            +  "  <if test='p1.ids != null and p1.ids.length != 0'>                                                     "
            +  "    AND t.id in                                                                                         "
            +  "    <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>            "
            +  "      #{item}                                                                                           "
            +  "    </foreach>                                                                                          "
            +  "  </if>                                                                                                 "
            +  "  AND (t1.out_warehouse_id = #{p1.out_warehouse_id} or #{p1.out_warehouse_id} is null)                  "
            +  "  AND (t1.in_warehouse_id = #{p1.in_warehouse_id} or #{p1.in_warehouse_id} is null)                     "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.in_time_start},'%Y-%m-%d') or #{p1.in_time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.in_time_end},'%Y-%m-%d') or #{p1.in_time_end} is null)        "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "
            +  " </script>                                                                                              "
    )
    List<ProcessingRiceWarehouseInProgressExportVo> queryRicePageListExport(@Param("p1") ProcessingRiceWarehouseInProgressVo searchCondition);

    /**
     * 稻谷 查询导出数量
     * @param searchCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    count(1)                                                                                            "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN b_monitor_out t2 ON t2.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t3 ON t3.monitor_id = t.id                                               "
            +  "  LEFT JOIN m_warehouse t4 ON t1.out_warehouse_id = t4.id                                               "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t6 ON t6.monitor_id = t.id                                                 "
            +  "  LEFT JOIN m_warehouse t7 ON t7.id = t1.in_warehouse_id                                                "
            +  "  LEFT JOIN m_goods_spec t8 ON t1.sku_id = t8.id                                                        "
            +  "  LEFT JOIN b_order t9 on t9.serial_type in ('b_in_order','b_out_order') and t1.order_id = t9.id        "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
            +  "  AND IFNULL(t2.type,t3.type) = '"+ SystemConstants.MONITOR.B_MONITOR_OUT +"'                           "
            +  "  AND t4.warehouse_type IN ('"+ DictConstant.DICT_M_WAREHOUSE_TYPE_ZX +"', '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"')"
            +  "  AND IFNULL(t5.type,t6.type) = '"+ SystemConstants.MONITOR.B_MONITOR_IN +"'                            "
            +  "  AND t7.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_WD +"'                                 "
            +  "  AND t8.`goods_code` = '"+ SystemConstants.PRODUCT_COMM_CODE.COMM_RICE_CODE +"'                        "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') >= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time,'%Y-%m-%d') <= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') >= DATE_FORMAT(#{p1.in_time_start},'%Y-%m-%d') or #{p1.in_time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.in_time,'%Y-%m-%d') <= DATE_FORMAT(#{p1.in_time_end},'%Y-%m-%d') or #{p1.in_time_end} is null)        "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "
    )
    int selectRicePageExportNum(@Param("p1") ProcessingRiceWarehouseInProgressVo searchCondition);


    /**
     * 玉米
     * @param param
     * @param pageCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t.id,                                                                                               "
            +  "    t3.name supplier_name,                                                                              "
            +  "  	t2.contract_no,                                                                                     "
            +  "  	t4.`name` goods_name,                                                                               "
            +  "  	t.e_dt,                                                                                             "
            +  "  	t.vehicle_no,                                                                                       "
            +  "  	t.actual_count,                                                                                     "
            +  "  	ifnull(t9.short_name, t9.name) out_warehouse_name,                                                  "
            +  "  	ifnull(t8.short_name, t8.name) in_warehouse_name                                                    "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.in_id = t.id                                                          "
            +  "  LEFT JOIN b_monitor t6 ON t6.id = t5.monitor_id                                                       "
            +  "  LEFT JOIN b_schedule t7 ON t7.id = t6.schedule_id                                                     "
            +  "  LEFT JOIN m_warehouse t8 ON t7.in_warehouse_id = t8.id                                                "
            +  "  LEFT JOIN m_warehouse t9 ON t7.out_warehouse_id = t9.id                                               "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_MAIZE_CODE + "'                       "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)             "
            +  "  AND (t.e_dt_date <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)                 "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
            +  "     ${p1.params.dataScopeAnnotation}                                                                   "
    )
    IPage<ProcessingMaizeAndWheatWarehouseInProgressVo> queryMaizePageList(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo param, Page<ProcessingMaizeAndWheatWarehouseInProgressVo> pageCondition);

    /**
     * 玉米 合计
     * @param searchCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	IFNULL(SUM(t.actual_count), 0) actual_count                                                         "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_MAIZE_CODE + "'                       "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)             "
            +  "  AND (t.e_dt_date <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)                 "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "
    )
    ProcessingMaizeAndWheatWarehouseInProgressVo queryMaizePageListSum(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo searchCondition);

    /**
     * 玉米 导出数量
     * @param searchCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	count(1)                                                                                            "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_MAIZE_CODE + "'                       "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)             "
            +  "  AND (t.e_dt_date <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)                 "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "
    )
    int selectMaizeExportNum(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo searchCondition);

    /**
     * 玉米 导出
     * @param searchCondition
     * @return
     */
    @Select("<script>"
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    @row_num:= @row_num+ 1 as no,                                                                       "
            +  "    t3.name supplier_name,                                                                              "
            +  "  	t2.contract_no,                                                                                     "
            +  "  	t4.`name` goods_name,                                                                               "
            +  "  	t.e_dt,                                                                                             "
            +  "  	t.vehicle_no,                                                                                       "
            +  "  	t.actual_count,                                                                                     "
            +  "  	ifnull(t9.short_name, t9.name) out_warehouse_name,                                                  "
            +  "  	ifnull(t8.short_name, t8.name) in_warehouse_name                                                    "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.in_id = t.id                                                          "
            +  "  LEFT JOIN b_monitor t6 ON t6.id = t5.monitor_id                                                       "
            +  "  LEFT JOIN b_schedule t7 ON t7.id = t6.schedule_id                                                     "
            +  "  LEFT JOIN m_warehouse t8 ON t7.in_warehouse_id = t8.id                                                "
            +  "  LEFT JOIN m_warehouse t9 ON t7.out_warehouse_id = t9.id                                               "
            +  "   ,(select @row_num:=0) t10                                                                            "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_MAIZE_CODE + "'                       "
            +  "  <if test='p1.ids != null and p1.ids.length != 0'>                                                     "
            +  "    AND t.id in                                                                                         "
            +  "    <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>            "
            +  "      #{item}                                                                                           "
            +  "    </foreach>                                                                                          "
            +  "  </if>                                                                                                 "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date &gt;= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)          "
            +  "  AND (t.e_dt_date &lt;= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)              "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')   "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "
            +  "</script>                                                                                               "
    )
    List<ProcessingMaizeAndWheatWarehouseInProgressExportVo> queryMaizeListExport(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo searchCondition);

    /**
     * 小麦
     * @param param
     * @param pageCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t.id,                                                                                               "
            +  "    t3.name supplier_name,                                                                              "
            +  "  	t2.contract_no,                                                                                     "
            +  "  	t4.`name` goods_name,                                                                               "
            +  "  	t.e_dt,                                                                                             "
            +  "  	t.vehicle_no,                                                                                       "
            +  "  	t.actual_count,                                                                                     "
            +  "  	ifnull(t9.short_name, t9.name) out_warehouse_name,                                                  "
            +  "  	ifnull(t8.short_name, t8.name) in_warehouse_name                                                    "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.in_id = t.id                                                          "
            +  "  LEFT JOIN b_monitor t6 ON t6.id = t5.monitor_id                                                       "
            +  "  LEFT JOIN b_schedule t7 ON t7.id = t6.schedule_id                                                     "
            +  "  LEFT JOIN m_warehouse t8 ON t7.in_warehouse_id = t8.id                                                "
            +  "  LEFT JOIN m_warehouse t9 ON t7.out_warehouse_id = t9.id                                               "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_WHEAT_CODE + "'                       "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)             "
            +  "  AND (t.e_dt_date <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)                 "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')      "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "
    )
    IPage<ProcessingMaizeAndWheatWarehouseInProgressVo> queryWheatPageList(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo param, Page<ProcessingMaizeAndWheatWarehouseInProgressVo> pageCondition);

    /**
     * 小麦 求和
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	IFNULL(SUM(t.actual_count), 0) actual_count                                                         "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_WHEAT_CODE + "'                       "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)             "
            +  "  AND (t.e_dt_date <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)                 "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')   "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "
    )
    ProcessingMaizeAndWheatWarehouseInProgressVo queryWheatPageListSum(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo param);

    /**
     * 小麦 导出
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	count(1)                                                                                            "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_WHEAT_CODE + "'                       "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)             "
            +  "  AND (t.e_dt_date <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)                 "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')   "
            + "     ${p1.params.dataScopeAnnotation}                                                                    "

    )
    int selectWheatExportNum(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo param);

    @Select("<script>"
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    @row_num:= @row_num+ 1 as no,                                                                       "
            +  "    t3.`name` supplier_name,                                                                            "
            +  "  	t2.contract_no,                                                                                     "
            +  "  	t4.`name` goods_name,                                                                               "
            +  "  	t.e_dt,                                                                                             "
            +  "  	t.vehicle_no,                                                                                       "
            +  "  	t.actual_count,                                                                                     "
            +  "  	ifnull(t9.short_name, t9.name) out_warehouse_name,                                                  "
            +  "  	ifnull(t8.short_name, t8.name) in_warehouse_name                                                    "
            +  "  FROM b_in t                                                                                           "
            +  "  LEFT JOIN b_in_extra t1 ON t1.in_id = t.id                                                            "
            +  "  LEFT JOIN b_order t2 on t1.order_id = t2.serial_id and t1.order_type = t2.serial_type                 "
            +  "  LEFT JOIN m_customer t3 ON t2.customer_id = t3.id                                                     "
            +  "  LEFT JOIN m_goods_spec t4 ON t4.id = t.sku_id                                                         "
            +  "  LEFT JOIN b_monitor_in t5 ON t5.in_id = t.id                                                          "
            +  "  LEFT JOIN b_monitor t6 ON t6.id = t5.monitor_id                                                       "
            +  "  LEFT JOIN b_schedule t7 ON t7.id = t6.schedule_id                                                     "
            +  "  LEFT JOIN m_warehouse t8 ON t7.in_warehouse_id = t8.id                                                "
            +  "  LEFT JOIN m_warehouse t9 ON t7.out_warehouse_id = t9.id                                               "
            +  "   ,(select @row_num:=0) t10                                                                            "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_IN_STATUS_TWO +"'                                       "
            +  "  AND t.type IN ('"+ DictConstant.DICT_B_IN_TYPE_SIX +"', '"+ DictConstant.DICT_B_IN_TYPE_ZERO +"')        "
            +  "  AND t4.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_WHEAT_CODE + "'                       "
            +  "  <if test='p1.ids != null and p1.ids.length != 0'>                                                     "
            +  "    AND t.id in                                                                                         "
            +  "    <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>            "
            +  "      #{item}                                                                                           "
            +  "    </foreach>                                                                                          "
            +  "  </if>                                                                                                 "
            +  "  AND (IFNULL(t3.short_name,t3.`name`) LIKE CONCAT('%', #{p1.supplier_name}, '%') or #{p1.supplier_name} is null or #{p1.supplier_name} = '')"
            +  "  AND (t.e_dt_date &gt;= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)          "
            +  "  AND (t.e_dt_date &lt;= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)              "
            +  "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')   "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
            +  " </script>                                                                                              "
    )
    List<ProcessingMaizeAndWheatWarehouseInProgressExportVo> queryWheatListExport(@Param("p1") ProcessingMaizeAndWheatWarehouseInProgressVo searchCondition);


    /**
     * 稻壳
     * @param param
     * @param pageCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t.id,                                                                                               "
            +  "  	t1.`name` goods_name,                                                                               "
            +  "  	t5.`name` client_name,                                                                              "
            +  "  	IFNULL( t3.contract_no, t4.contract_no ) contract_no,                                               "
            +  "  	t.e_dt,                                                                                             "
            +  "  	t.vehicle_no,                                                                                       "
            +  "  	t.gross_weight,                                                                                     "
            +  "  	t.tare_weight,                                                                                      "
            +  "  	t.actual_count                                                                                      "
            +  "  FROM                                                                                                  "
            +  "  	b_out t                                                                                             "
            +  "  	LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                       "
            +  "  	LEFT JOIN b_out_plan_detail t2 ON t.plan_detail_id = t2.id                                          "
            +  "  	LEFT JOIN b_order t3 ON t2.order_id = t3.serial_id                                                  "
            +  "  	AND t2.order_type = t3.serial_type                                                                  "
            +  "  	LEFT JOIN b_out_extra t4 ON t.id = t4.out_id                                                        "
            +  "  	LEFT JOIN m_customer t5 ON t3.customer_id = t5.id                                                     "
            +  "  WHERE                                                                                                 "
//            +  "  	t.`status` = '"+ DictConstant.DICT_B_OUT_STATUS_PASSED + "'                                         "
//            +  "  	AND t.type = '"+ DictConstant.DICT_B_OUT_TYPE_XS +"'                                                "
            +  "  	AND t1.goods_code = '"+  SystemConstants.PRODUCT_COMM_CODE.COMM_RICE_HULL_CODE +"'                  "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (IFNULL( t5.`name`, t5.short_name) LIKE CONCAT('%', #{p1.client_name}, '%') or #{p1.client_name} is null or #{p1.client_name} = '')     "
            +  "  AND (DATE_FORMAT(t.e_dt, '%Y-%m-%d') >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)      "
            +  "  AND (DATE_FORMAT(t.e_dt, '%Y-%m-%d') <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)          "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    IPage<ProcessingRiceHullWarehouseOutDetailVo> queryRiceHullPageList(@Param("p1") ProcessingRiceHullWarehouseOutDetailVo param, Page<ProcessingMaizeAndWheatWarehouseInProgressVo> pageCondition);

    /**
     * 稻壳 导出
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	count(1)                                                                                            "
            +  "  FROM                                                                                                  "
            +  "  	b_out t                                                                                             "
            +  "  	LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                       "
            +  "  	LEFT JOIN b_out_plan_detail t2 ON t.plan_detail_id = t2.id                                          "
            +  "  	LEFT JOIN b_order t3 ON t2.order_id = t3.serial_id                                                  "
            +  "  	AND t2.order_type = t3.serial_type                                                                  "
            +  "  	LEFT JOIN b_out_extra t4 ON t.id = t4.out_id                                                        "
            +  "  	LEFT JOIN m_customer t5 ON t3.customer_id = t5.id                                                     "
            +  "  WHERE                                                                                                 "
//            +  "  	t.`status` = '"+ DictConstant.DICT_B_OUT_STATUS_PASSED + "'                                         "
//            +  "  	AND t.type = '"+ DictConstant.DICT_B_OUT_TYPE_XS +"'                                                "
            +  "  	AND t1.goods_code = '"+  SystemConstants.PRODUCT_COMM_CODE.COMM_RICE_HULL_CODE +"'                  "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (IFNULL( t5.`name`, t5.short_name ) LIKE CONCAT('%', #{p1.client_name}, '%') or #{p1.client_name} is null or #{p1.client_name} = '')     "
            +  "  AND (DATE_FORMAT(t.e_dt, '%Y-%m-%d') >= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)      "
            +  "  AND (DATE_FORMAT(t.e_dt, '%Y-%m-%d') <= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)          "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    int selectRicehullExportNum(@Param("p1") ProcessingRiceHullWarehouseOutDetailVo param);

    /**
     * 稻壳 导出
     * @param param
     * @return
     */
    @Select("<script>"
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    @row_num:= @row_num+ 1 as no,                                                                       "
            +  "  	t1.`name` goods_name,                                                                               "
            +  "  	t5.`name` client_name,                                                                              "
            +  "  	IFNULL( t3.contract_no, t4.contract_no ) contract_no,                                               "
            +  "  	t.e_dt,                                                                                             "
            +  "  	t.vehicle_no,                                                                                       "
            +  "  	t.gross_weight,                                                                                     "
            +  "  	t.tare_weight,                                                                                      "
            +  "  	t.actual_count                                                                                      "
            +  "  FROM                                                                                                  "
            +  "  	b_out t                                                                                             "
            +  "  	LEFT JOIN m_goods_spec t1 ON t.sku_id = t1.id                                                       "
            +  "  	LEFT JOIN b_out_plan_detail t2 ON t.plan_detail_id = t2.id                                          "
            +  "  	LEFT JOIN b_order t3 ON t2.order_id = t3.serial_id                                                  "
            +  "  	AND t2.order_type = t3.serial_type                                                                  "
            +  "  	LEFT JOIN b_out_extra t4 ON t.id = t4.out_id                                                        "
            +  "  	LEFT JOIN m_customer t5 ON t3.customer_id = t5.id                                                     "
            +  "   ,(select @row_num:=0) t6                                                                             "
            +  "  WHERE                                                                                                 "
//            +  "  	t.`status` = '"+ DictConstant.DICT_B_OUT_STATUS_PASSED + "'                                         "
//            +  "  	AND t.type = '"+ DictConstant.DICT_B_OUT_TYPE_XS +"'                                                "
            +  "  	AND t1.goods_code = '"+  SystemConstants.PRODUCT_COMM_CODE.COMM_RICE_HULL_CODE +"'                  "
            +  "  <if test='p1.ids != null and p1.ids.length != 0'>                                                     "
            +  "    AND t.id in                                                                                         "
            +  "    <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>            "
            +  "      #{item}                                                                                           "
            +  "    </foreach>                                                                                          "
            +  "  </if>                                                                                                 "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (IFNULL( t5.`name`, t5.short_name ) LIKE CONCAT('%', #{p1.client_name}, '%') or #{p1.client_name} is null or #{p1.client_name} = '')     "
            +  "  AND (DATE_FORMAT(t.e_dt, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.e_dt_start},'%Y-%m-%d') or #{p1.e_dt_start} is null)      "
            +  "  AND (DATE_FORMAT(t.e_dt, '%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.e_dt_end},'%Y-%m-%d') or #{p1.e_dt_end} is null)          "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
            +  " </script>                                                                                              "
    )
    List<ProcessingRiceHullWarehouseOutDetailExportVo> queryRicehullListExport(@Param("p1") ProcessingRiceHullWarehouseOutDetailVo param);

    /**
     * 糙米出库进度表
     * @param param
     * @param pageCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t.id,                                                                                               "
            +  "    t2.`name` goods_name,                                                                               "
            +  "  	t3.`name` warehouse_name,                                                                           "
            +  "  	t8.`name` out_warehouse_name,                                                                           "
            +  "  	t4.waybill_contract_no waybill_code,                                                                "
            +  "  	t.out_time time,                                                                                    "
            +  "  	t5.`no` vehicle_no,                                                                                 "
            +  "  	IFNULL(t6.qty, t7.qty) qty                                                                          "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.in_warehouse_id = t3.id                                                "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                               "
            +  "  LEFT JOIN m_warehouse t8 ON t1.out_warehouse_id = t8.id                                               "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "',  "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX + "')                                                      "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.in_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "

    )
    IPage<ProcessingGrainWarehouseInOutDetailVo> queryGrainOutPageList(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param, Page<ProcessingGrainWarehouseInOutDetailVo> pageCondition);

    /**
     * 糙米出库进度表 求和
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	IFNULL(SUM(IFNULL(t6.qty, t7.qty)), 0) qty                                                          "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.in_warehouse_id = t3.id                                                "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                               "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "',  "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX + "')                                                      "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')       "
            +  "  AND (t1.in_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    ProcessingGrainWarehouseInOutDetailVo queryGrainOutPageListSum(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param);

    /**
     * 糙米出库进度表 求和
     * @param param
     * @return
     */

    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	count(1)                                                                                            "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.in_warehouse_id = t3.id                                                "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                               "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "',  "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX + "')                                                      "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.in_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                       "
    )
    int queryGrainOutExportNum(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param);

    /**
     * 糙米出库进度表 求和
     * @param param
     * @return
     */
    @Select("<script>"
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    @row_num:= @row_num+ 1 as no,                                                                       "
            +  "    t2.`name` goods_name,                                                                               "
            +  "  	t3.`name` warehouse_name,                                                                           "
            +  "  	t8.`name` out_warehouse_name,                                                                           "
            +  "  	t4.waybill_contract_no waybill_code,                                                                "
            +  "  	t.out_time time,                                                                                    "
            +  "  	t5.`no` vehicle_no,                                                                                 "
            +  "  	IFNULL(t6.qty, t7.qty) qty                                                                          "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.in_warehouse_id = t3.id                                                "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_out t6 ON t6.monitor_id = t.id                                                    "
            +  "  LEFT JOIN b_monitor_delivery t7 ON t7.monitor_id = t.id                                               "
            +  "  LEFT JOIN m_warehouse t8 ON t1.out_warehouse_id = t8.id                                               "
            +  "   ,(select @row_num:=0) t9                                                                             "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "',  "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX + "')                                                      "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            +  "  <if test='p1.ids != null and p1.ids.length != 0'>                                                     "
            +  "    AND t.id in                                                                                         "
            +  "    <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>            "
            +  "      #{item}                                                                                           "
            +  "    </foreach>                                                                                          "
            +  "  </if>                                                                                                 "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.in_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                       "
            +  " </script>                                                                                              "
    )
    List<ProcessingGrainWarehouseOutDetailExportVo> queryGrainOutExport(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param);

    /**
     * 糙米入库进度表
     *
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t.id,                                                                                               "
            +  "    t2.`name` goods_name,                                                                               "
            +  "  	t3.`name` warehouse_name,                                                                           "
            +  "  	t8.`name` out_warehouse_name,                                                                       "
            +  "  	t4.waybill_contract_no waybill_code,                                                                "
            +  "  	t.in_time time,                                                                                     "
            +  "  	t5.`no` vehicle_no,                                                                                 "
            +  "  	IFNULL(t6.qty, t7.qty) qty                                                                          "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.out_warehouse_id = t3.id                                               "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_in t6 ON t6.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t7 ON t7.monitor_id = t.id                                                 "
            +  "  LEFT JOIN m_warehouse t8 ON t1.in_warehouse_id = t8.id                                               "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_MONITOR_STATUS_SEVEN +"'                                   "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.out_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                       "
    )
    IPage<ProcessingGrainWarehouseInOutDetailVo> queryGrainInPageList(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param, Page<ProcessingGrainWarehouseInOutDetailVo> pageCondition);

    /**
     * 糙米入库进度表 合计
     *
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	IFNULL(SUM(IFNULL(t6.qty, t7.qty)), 0) qty                                                          "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.out_warehouse_id = t3.id                                               "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_in t6 ON t6.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t7 ON t7.monitor_id = t.id                                                 "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_MONITOR_STATUS_SEVEN +"'                                   "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.out_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    ProcessingGrainWarehouseInOutDetailVo queryGrainInListSum(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param);

    /**
     * 糙米入库进度表 导出数量查询
     *
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "  	count(1)                                                                                            "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.out_warehouse_id = t3.id                                               "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_in t6 ON t6.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t7 ON t7.monitor_id = t.id                                                 "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_MONITOR_STATUS_SEVEN +"'                                   "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.out_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    int exportGrainInListNum(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param);

    /**
     * 糙米入库进度表 导出
     *
     * @param param
     * @return
     */
    @Select("<script>"
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            +  "  SELECT                                                                                                "
            +  "    t.id,                                                                                               "
            +  "    @row_num:= @row_num+ 1 as no,                                                                       "
            +  "    t2.`name` goods_name,                                                                               "
            +  "  	t3.`name` warehouse_name,                                                                           "
            +  "  	t8.`name` in_warehouse_name,                                                                       "
            +  "  	t4.waybill_contract_no waybill_code,                                                                "
            +  "  	t.in_time time,                                                                                     "
            +  "  	t5.`no` vehicle_no,                                                                                 "
            +  "  	IFNULL(t6.qty, t7.qty) qty                                                                          "
            +  "  FROM b_monitor t                                                                                      "
            +  "  LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                      "
            +  "  LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            +  "  LEFT JOIN m_warehouse t3 ON t1.out_warehouse_id = t3.id                                               "
            +  "  LEFT JOIN b_schedule_info t4 ON t1.id = t4.schedule_id                                                "
            +  "  LEFT JOIN m_vehicle t5 ON t.vehicle_id = t5.id                                                        "
            +  "  LEFT JOIN b_monitor_in t6 ON t6.monitor_id = t.id                                                     "
            +  "  LEFT JOIN b_monitor_unload t7 ON t7.monitor_id = t.id                                                 "
            +  "  LEFT JOIN m_warehouse t8 ON t1.in_warehouse_id = t8.id                                                "
            +  "   ,(select @row_num:=0) t9                                                                             "
            +  "  WHERE t.`status` = '"+ DictConstant.DICT_B_MONITOR_STATUS_SEVEN +"'                                   "
            +  "  AND t2.goods_code = '" + SystemConstants.PRODUCT_COMM_CODE.COMM_GRAIN_CODE +"'                        "
            +  "  <if test='p1.ids != null and p1.ids.length != 0'>                                                     "
            +  "    AND t.id in                                                                                         "
            +  "    <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>            "
            +  "      #{item}                                                                                           "
            +  "    </foreach>                                                                                          "
            +  "  </if>                                                                                                 "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.out_warehouse_id = #{p1.warehouse_id} or #{p1.warehouse_id} is null or #{p1.warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.time_start},'%Y-%m-%d') or #{p1.time_start} is null)    "
            +  "  AND (DATE_FORMAT(t.in_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.time_end},'%Y-%m-%d') or #{p1.time_end} is null)        "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
            +  " </script>                                                                                              "
    )
    List<ProcessingGrainWarehouseInDetailExportVo> exportGrainInList(@Param("p1") ProcessingGrainWarehouseInOutDetailVo param);

    /**
     * 混合物 列表
     * @param param
     * @param pageCondition
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                                "
            + "  SELECT                                                                                                               "
            + "  	t.id,                                                                                                             "
            + "  	t2.`name` goods_name,                                                                                             "
            + "  	t3.`name`  in_warehouse_name,                                                                                     "
            + "  	IFNULL( t4.qty, t5.qty ) qty,                                                                                     "
            + "  	ifnull(t10.contract_no,t1.contract_no) contract_no,                                                               "
            + "  	t.out_time,                                                                                                       "
            + "  	t11.`no` vehicle_no,                                                                                              "
            + "  	t13.name out_owner_name,                                                                                          "
            + "  	t14.name out_warehouse_name,                                                                                      "
            + "  	t15.customer_name ,                                                                                               "
            + "  	ifnull(t16.qty,0) return_qty,                                                                                "
            + "  	IFNULL( t4.qty, t5.qty ) - ifnull(t16.qty,0)  as  actual_count_return,                                       "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100510' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t6.ricehull_router / 100, 4 ),0)        "
            + "  		WHEN t2.goods_code = 'zlsd-0100508' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t8.ricehull_router / 100, 4 ),0)  ELSE 0"
            + "  	END ricehull_qty,                                                                                                 "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100510' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t6.maize_router / 100, 4 ),0)           "
            + "  		WHEN t2.goods_code = '19' THEN                                                                                "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t9.maize_router / 100, 4 ),0) ELSE 0    "
            + "  	END maize_qty,                                                                                                    "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100509' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t7.rice_router / 100, 4 ),0)            "
            + "  		WHEN t2.goods_code = '19' THEN                                                                                "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t9.rice_router / 100, 4 ),0) ELSE 0     "
            + "  	END rice_qty,                                                                                                     "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100509' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t7.wheat_router / 100, 4 ),0)                                        "
            + "  		WHEN t2.goods_code = 'zlsd-0100508' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t8.wheat_router / 100, 4 ),0)  ELSE 0                                "
            + "  	END wheat_qty                                                                                                     "
            + "  FROM                                                                                                                 "
            + "  	b_monitor t                                                                                                       "
            + "  	LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                                  "
            + "  	LEFT JOIN m_goods_spec t2 ON t2.id = t1.sku_id                                                                    "
            + "  	LEFT JOIN m_warehouse t3 ON t3.id = t1.in_warehouse_id                                                            "
            + "  	LEFT JOIN b_monitor_out t4 ON t.id = t4.monitor_id                                                                "
            + "  	LEFT JOIN b_monitor_delivery t5 ON t.id = t5.monitor_id                                                           "
            + "  	LEFT JOIN b_order t10 on t10.serial_type in ('b_in_order','b_out_order') and t1.order_id = t10.id                 "
            + "  	LEFT JOIN m_vehicle t11 ON t.vehicle_id = t11.id                                                                  "
            + "     LEFT JOIN b_out_order t12 ON t12.id = t10.serial_id and t10.serial_type = 'b_out_order'                  "
            + "     LEFT JOIN m_owner t13 ON t12.owner_id = t13.id                                                                    "
            + "     LEFT JOIN m_warehouse t14 ON t14.id = t1.out_warehouse_id                                                         "
            + "     LEFT JOIN b_schedule_info t15 ON t1.id = t15.schedule_id                                                          "
            + "     LEFT JOIN b_return_relation t16 ON t16.serial_id = t.id AND t16.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "     AND  t16.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
//            + "  	-- 糙米玉米混合物（zlsd-0100510）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100510' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'CM-001'                                                                             "
//            + "             AND (DATE_FORMAT(tt2.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  		) ricehull_router,                                                                                            "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100506'                                                                       "
//            + "             AND (DATE_FORMAT(tt2.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  		) maize_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
//            + "             AND (DATE_FORMAT(t1.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100510'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'CM-001'                                                                            "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100506'                                                                      "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')         "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t6 ON t6.goods_code = t2.goods_code                                                                             "
//            + "  	-- 稻谷小麦混合物（zlsd-0100509）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100509' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100507-3'                                                                     "
//            + "             AND (DATE_FORMAT(tt2.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')         "
            + "  		) rice_router,                                                                                                "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
//            + "             AND (DATE_FORMAT(tt2.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			AND tt3.goods_code = 'zlsd-0100505'                                                                       "
            + "  		) wheat_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100509'                                                                      "
//            + "             AND (DATE_FORMAT(t1.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100507-3'                                                                    "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100505'                                                                      "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t7 ON t7.goods_code = t2.goods_code                                                                             "
//            + "  	-- 糙米小麦混合物（zlsd-0100508）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100508' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'CM-001'                                                                             "
//            + "             AND (DATE_FORMAT(tt2.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  		) ricehull_router,                                                                                            "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100505'                                                                       "
//            + "             AND (DATE_FORMAT(tt2.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  		) wheat_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100508'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
//            + "             AND (DATE_FORMAT(t1.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'CM-001'                                                                            "
            + "  				AND t.id = t3.wo_id                                                                                   "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100505'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t8 ON t8.goods_code = t2.goods_code                                                                             "
//            + "  	-- 稻谷玉米混合物（19）                                                                                           "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'19' goods_code,                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100507-3'                                                                     "
//            + "             AND (DATE_FORMAT(tt3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  		) rice_router,                                                                                                "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100506'                                                                       "
//            + "             AND (DATE_FORMAT(tt2.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  		) maize_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = '19'                                                                                "
            + "  				AND t.id = t1.wo_id                                                                                   "
//            + "             AND (DATE_FORMAT(t1.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100507-3'                                                                    "
            + "  				AND t.id = t3.wo_id                                                                                   "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100506'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
//            + "             AND (DATE_FORMAT(t3.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')        "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t9 ON t8.goods_code = t2.goods_code                                                                             "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
            + "  	AND t2.goods_code IN ( 'zlsd-0100509', 'zlsd-0100510', 'zlsd-0100508', '19' )                                     "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.in_warehouse_id = #{p1.in_warehouse_id} or #{p1.in_warehouse_id} is null or #{p1.in_warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            + "   AND t3.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_CL +"'                                               "
            +  " ${p1.params.dataScopeAnnotation}                                                                                     "
    )
    IPage<ProcessingComboWarehouseOutProgressVo> queryComboOutPageList(@Param("p1") ProcessingComboWarehouseOutProgressVo param, Page<ProcessingComboWarehouseOutProgressVo> pageCondition);

    /**
     * 混合物 求和
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            + "  SELECT                                                                                                               "
            + "  	IFNULL(SUM(IFNULL( t4.qty, t5.qty )),0) qty,                                                                      "
            + "  IFNULL(SUM(CASE                                                                                                      "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100510' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t6.ricehull_router / 100, 4 ),0)         "
            + "  		WHEN t2.goods_code = 'zlsd-0100508' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t8.ricehull_router / 100, 4 ),0) ELSE 0  "
            + "  	END), 0) ricehull_qty,                                                                                            "
            + "  IFNULL(SUM(CASE                                                                                                      "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100510' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t6.maize_router / 100, 4 ),0)            "
            + "  		WHEN t2.goods_code = '19' THEN                                                                                "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t9.maize_router / 100, 4 ),0) ELSE 0     "
            + "  	END),0) maize_qty,                                                                                                "
            + "  IFNULL(SUM(CASE                                                                                                      "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100509' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t7.rice_router / 100, 4 ),0)             "
            + "  		WHEN t2.goods_code = '19' THEN                                                                                "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t9.rice_router / 100, 4 ),0) ELSE 0      "
            + "  	END),0) rice_qty,                                                                                                 "
            + "  IFNULL(SUM(CASE                                                                                                      "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100509' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t7.wheat_router / 100, 4 ),0)            "
            + "  		WHEN t2.goods_code = 'zlsd-0100508' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty )- ifnull( t16.qty, 0 )) * t8.wheat_router / 100, 4 ),0) ELSE 0     "
            + "  	END),0) wheat_qty                                                                                                 "
            + "  FROM                                                                                                                 "
            + "  	b_monitor t                                                                                                       "
            + "  	LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                                  "
            + "  	LEFT JOIN m_goods_spec t2 ON t2.id = t1.sku_id                                                                    "
            + "  	LEFT JOIN m_warehouse t3 ON t3.id = t1.in_warehouse_id                                                            "
            + "  	LEFT JOIN b_monitor_out t4 ON t.id = t4.monitor_id                                                                "
            + "  	LEFT JOIN b_monitor_delivery t5 ON t.id = t5.monitor_id                                                           "
            + "  	LEFT JOIN b_order t10 on t10.serial_type in ('b_in_order','b_out_order') and t1.order_id = t10.id                 "
            + "  	LEFT JOIN m_vehicle t11 ON t.vehicle_id = t11.id                                                                  "
            + "     LEFT JOIN b_return_relation t16 ON t16.serial_id = t.id AND t16.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "     AND  t16.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
//            + "  	-- 糙米玉米混合物（zlsd-0100510）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100510' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'CM-001'                                                                             "
            + "  		) ricehull_router,                                                                                            "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100506'                                                                       "
            + "  		) maize_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100510'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'CM-001'                                                                            "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100506'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t6 ON t6.goods_code = t2.goods_code                                                                             "
//            + "  	-- 稻谷小麦混合物（zlsd-0100509）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100509' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100507-3'                                                                     "
            + "  		) rice_router,                                                                                                "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100505'                                                                       "
            + "  		) wheat_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100509'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100507-3'                                                                    "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100505'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t7 ON t7.goods_code = t2.goods_code                                                                             "
//            + "  	-- 糙米小麦混合物（zlsd-0100508）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100508' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'CM-001'                                                                             "
            + "  		) ricehull_router,                                                                                            "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100505'                                                                       "
            + "  		) wheat_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100508'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'CM-001'                                                                            "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100505'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t8 ON t8.goods_code = t2.goods_code                                                                             "
//            + "  	-- 稻谷玉米混合物（19）                                                                                           "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'19' goods_code,                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100507-3'                                                                     "
            + "  		) rice_router,                                                                                                "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100506'                                                                       "
            + "  		) maize_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = '19'                                                                                "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100507-3'                                                                    "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100506'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t9 ON t8.goods_code = t2.goods_code                                                                             "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
            + "  	AND t2.goods_code IN ( 'zlsd-0100509', 'zlsd-0100510', 'zlsd-0100508', '19' )                                     "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.in_warehouse_id = #{p1.in_warehouse_id} or #{p1.in_warehouse_id} is null or #{p1.in_warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            + "   AND t3.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_CL +"'                                               "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    ProcessingComboWarehouseOutProgressVo queryComboOutListSum(@Param("p1") ProcessingComboWarehouseOutProgressVo param);

    /**
     * 混合物 查询导出数量
     * @param param
     * @return
     */
    @Select(""
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            + "  SELECT                                                                                                               "
            + "  	count(1)                                                                                                          "
            + "  FROM                                                                                                                 "
            + "  	b_monitor t                                                                                                       "
            + "  	LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                                  "
            + "  	LEFT JOIN m_goods_spec t2 ON t2.id = t1.sku_id                                                                    "
            + "  	LEFT JOIN m_warehouse t3 ON t3.id = t1.in_warehouse_id                                                            "
            + "  	LEFT JOIN b_monitor_out t4 ON t.id = t4.monitor_id                                                                "
            + "  	LEFT JOIN b_monitor_delivery t5 ON t.id = t5.monitor_id                                                           "
            + "  	LEFT JOIN b_order t10 on t10.serial_type in ('b_in_order','b_out_order') and t1.order_id = t10.id                 "
            + "  	LEFT JOIN m_vehicle t11 ON t.vehicle_id = t11.id                                                                  "
            +  "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
            + "  	AND t2.goods_code IN ( 'zlsd-0100509', 'zlsd-0100510', 'zlsd-0100508', '19' )                                     "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') >= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.in_warehouse_id = #{p1.in_warehouse_id} or #{p1.in_warehouse_id} is null or #{p1.in_warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') >= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') <= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            + "   AND t3.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_CL +"'                                               "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
    )
    int exportComboListNum(@Param("p1") ProcessingComboWarehouseOutProgressVo param);

    /**
     * 混合物 导出
     * @param param
     * @return
     */
    @Select("<script>"
            +  " ${p1.params.dataScopeAnnotation_with}                                                                  "
            + "  SELECT                                                                                                               "
            + "  	t.id,                                                                                                             "
            + "  	t2.`name` goods_name,                                                                                             "
            + "  	t3.`name`  in_warehouse_name,                                                                                     "
            + "  	IFNULL( t4.qty, t5.qty ) qty,                                                                                     "
            + "  	ifnull(t10.contract_no,t1.contract_no) contract_no,                                                               "
            + "  	t.out_time,                                                                                                       "
            + "  	t11.`no` vehicle_no,                                                                                              "
            + "  	t13.name out_owner_name,                                                                                          "
            + "  	t14.name out_warehouse_name,                                                                                      "
            + "  	t15.customer_name ,                                                                                               "
            + "  	ifnull(t16.qty,0) return_qty,                                                                                "
            + "  	IFNULL( t4.qty, t5.qty ) - ifnull(t16.qty,0)  as  actual_count_return,                                       "
            + "    @row_num:= @row_num+ 1 as no,                                                                                      "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100510' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t6.ricehull_router / 100, 4 ),0)        "
            + "  		WHEN t2.goods_code = 'zlsd-0100508' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t8.ricehull_router / 100, 4 ),0)  ELSE 0"
            + "  	END ricehull_qty,                                                                                                 "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100510' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t6.maize_router / 100, 4 ),0)           "
            + "  		WHEN t2.goods_code = '19' THEN                                                                                "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t9.maize_router / 100, 4 ),0) ELSE 0    "
            + "  	END maize_qty,                                                                                                    "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100509' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t7.rice_router / 100, 4 ),0)            "
            + "  		WHEN t2.goods_code = '19' THEN                                                                                "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t9.rice_router / 100, 4 ),0) ELSE 0     "
            + "  	END rice_qty,                                                                                                     "
            + "  CASE                                                                                                                 "
            + "  		                                                                                                              "
            + "  		WHEN t2.goods_code = 'zlsd-0100509' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t7.wheat_router / 100, 4 ),0)                                        "
            + "  		WHEN t2.goods_code = 'zlsd-0100508' THEN                                                                      "
            + "  		IFNULL(round((IFNULL( t4.qty, t5.qty ) - ifnull( t16.qty, 0 )) * t8.wheat_router / 100, 4 ),0)  ELSE 0                                "
            + "  	END wheat_qty                                                                                                     "
            + "  FROM                                                                                                                 "
            + "  	b_monitor t                                                                                                       "
            + "  	LEFT JOIN b_schedule t1 ON t.schedule_id = t1.id                                                                  "
            + "  	LEFT JOIN m_goods_spec t2 ON t2.id = t1.sku_id                                                                    "
            + "  	LEFT JOIN m_warehouse t3 ON t3.id = t1.in_warehouse_id                                                            "
            + "  	LEFT JOIN b_monitor_out t4 ON t.id = t4.monitor_id                                                                "
            + "  	LEFT JOIN b_monitor_delivery t5 ON t.id = t5.monitor_id                                                           "
            + "  	LEFT JOIN b_order t10 on t10.serial_type in ('b_in_order','b_out_order') and t1.order_id = t10.id                 "
            + "  	LEFT JOIN m_vehicle t11 ON t.vehicle_id = t11.id                                                                  "
            + "     LEFT JOIN b_out_order t12 ON t12.id = t10.serial_id and t10.serial_type = 'b_out_order'                  "
            + "     LEFT JOIN m_owner t13 ON t12.owner_id = t13.id                                                                    "
            + "     LEFT JOIN m_warehouse t14 ON t14.id = t1.out_warehouse_id                                                         "
            + "     LEFT JOIN b_schedule_info t15 ON t1.id = t15.schedule_id                                                          "
            + "     LEFT JOIN b_return_relation t16 ON t16.serial_id = t.id AND t16.serial_type = '"+ SystemConstants.SERIAL_TYPE.B_MONITOR+"'                     "
            + "     AND  t16.STATUS = '"+ DictConstant.DICT_B_RETURN_RELATION_STATUS_TG +"'                                                                        "
//            + "  	-- 糙米玉米混合物（zlsd-0100510）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100510' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'CM-001'                                                                             "
            + "  		) ricehull_router,                                                                                            "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100506'                                                                       "
            + "  		) maize_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100510'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'CM-001'                                                                            "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100506'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t6 ON t6.goods_code = t2.goods_code                                                                             "
//            + "  	-- 稻谷小麦混合物（zlsd-0100509）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100509' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100507-3'                                                                     "
            + "  		) rice_router,                                                                                                "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100505'                                                                       "
            + "  		) wheat_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100509'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100507-3'                                                                    "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100505'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t7 ON t7.goods_code = t2.goods_code                                                                             "
//            + "  	-- 糙米小麦混合物（zlsd-0100508）                                                                                 "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'zlsd-0100508' goods_code,                                                                                    "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'CM-001'                                                                             "
            + "  		) ricehull_router,                                                                                            "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100505'                                                                       "
            + "  		) wheat_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = 'zlsd-0100508'                                                                      "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'CM-001'                                                                            "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100505'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t8 ON t8.goods_code = t2.goods_code                                                                             "
//            + "  	-- 稻谷玉米混合物（19）                                                                                           "
            + "  	LEFT JOIN (                                                                                                       "
            + "  	SELECT                                                                                                            "
            + "  		tt1.id,                                                                                                       "
            + "  		'19' goods_code,                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100507-3'                                                                     "
            + "  		) rice_router,                                                                                                "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			tt2.wo_router                                                                                             "
            + "  		FROM                                                                                                          "
            + "  			b_wo_material tt2                                                                                         "
            + "  			LEFT JOIN m_goods_spec tt3 ON tt2.sku_id = tt3.id                                                         "
            + "  		WHERE                                                                                                         "
            + "  			tt2.wo_id = tt1.id                                                                                        "
            + "  			AND tt3.goods_code = 'zlsd-0100506'                                                                       "
            + "  		) maize_router                                                                                                "
            + "  	FROM                                                                                                              "
            + "  		(                                                                                                             "
            + "  		SELECT                                                                                                        "
            + "  			t.`id`                                                                                                    "
            + "  		FROM                                                                                                          "
            + "  			b_wo t                                                                                                    "
            + "  		WHERE                                                                                                         "
            + "  			t.`status` = '3'                                                                                          "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_product t1                                                                                       "
            + "  				LEFT JOIN m_goods_spec t2 ON t1.sku_id = t2.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t2.`goods_code` = '19'                                                                                "
            + "  				AND t.id = t1.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100507-3'                                                                    "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  			AND EXISTS (                                                                                              "
            + "  			SELECT                                                                                                    "
            + "  				1                                                                                                     "
            + "  			FROM                                                                                                      "
            + "  				b_wo_material t3                                                                                      "
            + "  				LEFT JOIN m_goods_spec t4 ON t3.sku_id = t4.id                                                        "
            + "  			WHERE                                                                                                     "
            + "  				t4.`goods_code` = 'zlsd-0100506'                                                                      "
            + "  				AND t.id = t3.wo_id                                                                                   "
            + "  			)                                                                                                         "
            + "  		ORDER BY                                                                                                      "
            + "  			t.e_time DESC                                                                                             "
            + "  			LIMIT 1                                                                                                   "
            + "  		) tt1                                                                                                         "
            + "  	) t9 ON t8.goods_code = t2.goods_code                                                                             "
            + "   ,(select @row_num:=0) t10                                                                            "
            + "  WHERE t.`status` IN ('"+ DictConstant.DICT_B_MONITOR_STATUS_THREE +"', '"+ DictConstant.DICT_B_MONITOR_STATUS_FOUR +"',"
            +  "  '"+ DictConstant.DICT_B_MONITOR_STATUS_SIX +"',                                                       "
            + "  '"+ DictConstant.DICT_B_MONITOR_STATUS_FIVE +"', '" + DictConstant.DICT_B_MONITOR_STATUS_SEVEN + "')  "
            + "  	AND t2.goods_code IN ( 'zlsd-0100509', 'zlsd-0100510', 'zlsd-0100508', '19' )                      "
            + "  <if test='p1.ids != null and p1.ids.length != 0'>                                                     "
            + "    AND t.id in                                                                                         "
            + "    <foreach collection='p1.ids' item='item' index='index' open='(' separator=',' close=')'>            "
            + "      #{item}                                                                                           "
            + "    </foreach>                                                                                          "
            + "  </if>                                                                                                 "
            + "  AND (DATE_FORMAT(t.c_time,'%Y-%m-%d') &gt;= #{p1.batch} or #{p1.batch} is null or #{p1.batch} = '')                     "
            +  "  AND (t1.in_warehouse_id = #{p1.in_warehouse_id} or #{p1.in_warehouse_id} is null or #{p1.in_warehouse_id} = '')     "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{p1.out_time_start},'%Y-%m-%d') or #{p1.out_time_start} is null) "
            +  "  AND (DATE_FORMAT(t.out_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{p1.out_time_end},'%Y-%m-%d') or #{p1.out_time_end} is null)     "
            + "   AND t3.warehouse_type = '"+ DictConstant.DICT_M_WAREHOUSE_TYPE_CL +"'                                               "
            +  " ${p1.params.dataScopeAnnotation}                                                                  "
            + "</script>"
    )
    List<ProcessingComboWarehouseOutProgressExportVo> exportComboList(@Param("p1") ProcessingComboWarehouseOutProgressVo param);
}
